package com.maddox.relax.model;

import android.content.pm.PackageManager;
import android.net.Uri;

import com.maddox.relax.util.PBitmapUtils;

import java.io.Serializable;

/**
 * 图片的封装信息
 */
public class ImageInfo implements Serializable {

    private static final long serialVersionUID = 5458332493366878966L;
    //媒体文件的id
    public long id;
    //图片的宽度
    public int width;
    //图片的高度
    public int height;
    //图片的创建或者更新时间
    public long time;
    //针对视频类型的时长
    public long duration;
    //文件类型
    public String mimeType;
    //更新时间的格式化
    public String timeFormat;
    //时长的格式化
    public String durationFormat;
    //是否是视频文件
    public boolean isVideo = false;
    //是否是原图
    public boolean isOriginalImage = true;
    //拍照文件名称
    public String  fileName;
    //相册文件名称
    public String displayName;

    //视频缩略图
    public String videoImageUri;
    //文件的绝对路径,适配老项目
    public String filePath;
    //文件的Uri路径,媒体库一定会有Uri
    public String uriPath;
    //用于相册选择
    public boolean isSelect = false;
    public boolean isPress = false;
    public int selectIndex = -1;

    public ImageInfo() {
    }


    public ImageInfo copy() {
        ImageInfo newItem = new ImageInfo();
        newItem.filePath = this.filePath;
        newItem.isVideo = this.isVideo;
        newItem.duration = this.duration;
        newItem.height = this.height;
        newItem.width = this.width;
        newItem.durationFormat = this.durationFormat;
        newItem.id = this.id;
        newItem.isPress = false;
        newItem.isSelect = false;
        newItem.isOriginalImage = isOriginalImage;
        return newItem;
    }

    //先判断uriPath,不存在再去根据绝对路径获取
    public Uri getUri() {
        if (uriPath != null && uriPath.length() > 0) {
            return Uri.parse(uriPath);
        }

        if (isUriPath()) {
            return Uri.parse(filePath);
        }

        return PBitmapUtils.getContentUri(mimeType, id);
    }



    public boolean isUriPath() {
        return filePath != null && filePath.contains("content://");
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public String getTimeFormat() {
        return timeFormat;
    }

    public void setTimeFormat(String timeFormat) {
        this.timeFormat = timeFormat;
    }

    public String getDurationFormat() {
        return durationFormat;
    }

    public void setDurationFormat(String durationFormat) {
        this.durationFormat = durationFormat;
    }

    public boolean isVideo() {
        return isVideo;
    }

    public void setVideo(boolean video) {
        isVideo = video;
    }

    public boolean isOriginalImage() {
        return isOriginalImage;
    }

    public void setOriginalImage(boolean originalImage) {
        isOriginalImage = originalImage;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getVideoImageUri() {
        return videoImageUri;
    }

    public void setVideoImageUri(String videoImageUri) {
        this.videoImageUri = videoImageUri;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }



    public void setUriPath(String uriPath) {
        this.uriPath = uriPath;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    public boolean isPress() {
        return isPress;
    }

    public void setPress(boolean press) {
        isPress = press;
    }

    public int getSelectIndex() {
        return selectIndex;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }
}
